/**
 * Created by Administrator on 2017/8/30 0030.
 */
var trendSelectPath="http://192.168.0.161:9096/web"
var trendPath="http://47.105.128.56:9097/api/interact/web"
operateFormatter = function (value, row, index) {
    return [
        '<a class="comment" href="javascript:void(0)" title="评论"><i class="glyphicon glyphicon-list-alt"></i></a>' +
        '&nbsp;&nbsp;&nbsp;&nbsp;' +
        '<a class="remove" href="javascript:void(0)" title="删除"><i class="fa fa-trash-o"></i></a>'
    ].join('');
};
commentOperateFormatter = function (value, row, index) {
    return [
        '<a class="removeComment" href="javascript:void(0)" title="删除"><i class="fa fa-trash-o"></i></a>'
    ].join('');
}

operateImages = function (value, row, index) {
    if (row.trendsImages == null || row.trendsImages == '') {
        return ["-"].join('');
    } else {
        return ['<a class="showImgs" href="javascript:void(0)" title="查看图片"><i >点击查看</i></a>'].join('');
    }
};

operateAvPic = function (value, row, index) {
    if (row.videoPic == null || row.videoPic == '') {
        return ["-"].join('');
    } else {
        return ['<a class="showVideoImg" href="javascript:void(0)" title="查看图片"><i >点击查看</i></a>'].join('');
    }
};

operateVideos = function (value, row, index) {
    if (row.trendsVideo == null || row.trendsVideo == '') {
        return ["-"].join('');
    } else {
        return ['<a class="showVideo" href="javascript:void(0)" title="查看视频"><i >点击查看</i></a>'].join('');
    }
};

operateContent = function (value, row, index) {
    if (row.comment == null || row.comment == '') {
        return ["-"].join('');
    } else {
        return ['<a class="showContent" href="javascript:void(0)" title="查看内容"><i class="glyphicon glyphicon-list-alt"></i></a>'].join('');
    }
};

window.operateEvents = {
    'click .detail': function (e, value, row, index) {
        showDetail(row);
    },
    'click .comment': function (e, value, row, index) {
        showComments(row);
    },
    'click .replay': function (e, value, row, index) {
        showReplay(row);
    },
    'click .remove': function (e, value, row, index) {
        comment.showOperationTips("确定删除吗？", function () {
            comment.get(trendPath+'/deleteReport?reportId='+row.reportId+'&trendId='+row.trendId,null, function (data) {
                if (data.res.code == 40000) {
                    // hint("删除成功");
                    comment.refresh();
                } else {
                    hint(data.res.msg);
                }
            });
        });
    },
    'click .removeComment': function (e, value, row, index) {
        comment.showOperationTips("确定删除吗？", function () {
            comment.get(trendPath+'/deleteComments?commentId='+row.commentId,null, function (data) {
                if (data.res.code == 40000) {
                    // hint("删除成功");
                    var table = $("#commentTable");
                    var url = $().AbsUrlParse(trendSelectPath+"/listComments?trendId=" + row.trendId);
                    table.bootstrapTable("refresh", {url: url});
                } else {
                    hint(data.res.msg);
                }
            });
        });
    },
    'click .showImgs': function (e, value, row, index) {
        showImages(row);
    },
    'click .showVideoImg': function (e, value, row, index) {
        var picPath = row.videoPic;
        showModel("detailVideoPic-div", function () {
            $("#videoPic").attr("src", File_Download_Url + picPath)
        });
    },
    'click .showVideo': function (e, value, row, index) {
        showVideo(row);
    },
    'click .showVoice': function (e, value, row, index) {
        showVoice(row);
    },
    'click .showContent': function (e, value, row, index) {
        showModel("content-div", function () {
            $("#content").val(row.comment);
        })
    }
};

var showImages = function (row) {
    showModel("detailImages-div", function () {
        $("#images").empty();
        var picPath = row.trendsImages;
        var picStr = '';
        var picPathArray = picPath.split(',');
        var url = File_Download_Url;
        $.each(picPathArray, function (n, value) {
            var everyUrl = url + "/" + value;
            picStr += '<img src="' + everyUrl + '" style="height: 400px;margin-bottom: 1%"/><br/>';
        });
        $("#images").append(picStr)
    });
};

var showVideo = function (row) {
    showModel("detailVideo-div", function () {
        var url = File_Download_Url + "/" + row.trendsVideo;
        $("#videoSource").attr("src", url);
    });
};
var showComments = function (row) {
    showModel("trendsComments-div", function () {
        var table = $("#commentTable");
        var url = $().AbsUrlParse(trendSelectPath+"/listComments?trendId=" + row.trendId);
        table.bootstrapTable("refresh", {url: url});
    });
};
//查询商品
bindClick("#trendSelect", function () {
    var userName = $("input[name=reportName]").val();

    var url = $().AbsUrlParse(trendSelectPath+"/listReport?userName=" + userName);
    $("#table").bootstrapTable("refresh", {url: url});
});